define(function(require){
	var main = require('/static/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		 colorList:[
            '#fb4155',
            '#ff8f6e',
            '#ffe659',
            '#79c3fc',
            '#6be6c1',
            '#516b91',
            '#edafda',
            '#7a7a7a',
        ],
		_init:function(){
			this.bindEvent();
		},
		bindEvent:function(){
			var _this = this;
			// 初始化左边菜单
		    $.ajax({
                type: "POST",
                url: "/analysis/spread-analyze",
                dataType: "json",
                success: function (ret) {
                	if(ret.IsBizSuccess){
	                	var data = [];
	                	var str = '';
	                	$.each(ret.Models,function(k,v){
	                		// data
	                		var DoneCount = _this.way(v.DoneCount) ; //订单数
	                		var FansCount = _this.way(v.FansCount);
	                		var PageView = _this.way(v.PageView); //浏览量
	                		var ShareCount = _this.way(v.ShareCount); //推广次数
	                		// var Saleroom = _this.way(v.Saleroom); //销售额
	                		var val = {
	                			value : ShareCount,
	                			name : v.AdTypeName
	                		}
	                		data.push(val);
	                		str +='<tr>\
			                        <td class="middle-align"><i class="fa fa-circle  m-r-15" style="color:'+_this.colorList[k]+'"></i>'+v.AdTypeName+'</td>\
			                        <td class="middle-align">'+FansCount+'</td>\
			                        <td class="middle-align">'+PageView+'</td>\
			                        <td class="middle-align">'+DoneCount+'</td>\
			                    </tr>'
	                	})
	                	if(data.length <= 0){
	                		$('.col-sm-5').hide();
	                	}else{
	                		$('.col-sm-5').show();
	                		_this.eacharsInit(data);
	                	}
	                	$('.table tbody').html(str);
                	}
                }
            });
		},
		way:function(data){
			return data ? data : 0;
		},
		eacharsInit:function(data){
			var _this = this;
			var chart = document.getElementById('echarts');
		    var echart = echarts.init(chart,'customed');
		    var option = {
		        tooltip : {
		            trigger: 'item'
		        },
		        color:_this.colorList,
		        legend: {
		            show:false,
		        },
		        series : [
		            {
		            	name: '推广次数',
		                type: 'pie',
		                radius : '50%',
		                center: ['50%', '30%'],
		                data:data,
		                itemStyle: {
		                    emphasis: {
		                        shadowBlur: 10,
		                        shadowOffsetX: 0,
		                        shadowColor: 'rgba(0, 0, 0, 0.5)'
		                    }
		                }
		            }
		        ]
		    };
		    echart.setOption(option);
		}


	}
	var a = new Cont();

})